/**
 * Copyright 2010 Victor Egea Hernando
 *
 * RockScript is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 * 
 * RockScript is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with RockScript.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef VM_MISCELLANEOUS_H_
#define VM_MISCELLANEOUS_H_

#include <corelib/misc/hash_map>
#include <set>

#include "../types.h"

#include "routine.h"
#include "vmclass.h"
#include "object.h"

namespace paper{

class vmachine;

class PAPER_API vm_error{

public:
    vm_error( corelib::uint32 id, const corelib::ustring &c, 
		const corelib::ustring &m, const corelib::ustring &e )
        :_rid( id ), _vmclass( c ), _method( m ), _error( e ){}

protected:
    corelib::uint32 _rid;
    const corelib::ustring &_vmclass;
    const corelib::ustring &_method; 
    const corelib::ustring &_error;

public:
	corelib::uint32 rid() const{return _rid; }
	const corelib::ustring &vmclass() const{return _vmclass;}
	const corelib::ustring &method() const{return _method;}
	const corelib::ustring &error() const{return _error;}

public:
	friend class vmachine;

};

class vmachine_hnd {

public:
    virtual void dynError( const vm_error &error ) = 0;
    virtual void open( const corelib::ustring &path ) = 0;
    virtual void compile( const corelib::ustring &path ) = 0;
    virtual corelib::uint8 getc( void ) = 0;
    virtual void close() = 0;

};


class vm_class_equalkey{

public:
    bool operator() ( const vm_class * const &k1, const vm_class * const &k2 ){
		return k1->name() == k2->name();
    }

};

class vm_class_hash{

public:
    corelib::uint32 operator() ( const vm_class * const &k1 ){
		return hash( k1->name() );
    }

protected:
    corelib::ustring_hash hash;

};

}; // namespace paper

#endif // VM_MISCELLANEOUS_H_

